package com.apes.fn.business.carAccident.repository;

import com.apes.fn.business.carAccident.modle.ClaimWorkOrder;
import com.apes.framework.jpa.repository.CustomRepository;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
 * @ClassName ClaimWorkOrderRepository
 * @Author wsj
 * @Date 2021/6/6 16:30
 * @description 数据层
 */
public interface ClaimWorkOrderRepository extends CustomRepository<ClaimWorkOrder,String> {
    /**
     * 统计该门店多少进行中的定损工单
     * @param dept
     * @return
     */
    @Query("select count(a.id) from ClaimWorkOrder  a where a.dept.id =:dept and a.state in ('create','accept')")
    int countValidForDept(@Param("dept")String dept);

    /**
     * 获取该门店所有进行中的定损工单详情
     * @param dept
     * @return
     */
    @Query("select a.id as id, a.carLicense as carLicense,a.phoneNumber as phoneNumber,a.reportPerson as reportPerson," +
            " a.carAccidentPlace as carAccidentPlace,a.carAccidentDate as carAccidentDate,a.storeStaffName as storeStaffName, " +
            " a.createDate as createDate,a.state as state," +
            " case when a.state = 'create' then '待接单' else '待勘察' end as stateName " +
            " from ClaimWorkOrder a where a.state in ('create','accept') and a.dept.id =:dept" +
            " order by a.createDate desc ")
    List<Map<String, Object>> getClaimWorkOrderForStore(@Param("dept") String dept);

    /**
     * 根据车险报案单号查询报案信息
     * @param carAccident
     * @return
     */
    @Query("select a.vehicleDuty.name as vehicleDuty,a.caseType.description as caseType,a.dangerType.name as dangerType," +
            " a.phoneNumber as phoneNumber ,a.carAccidentDescribe as carAccidentDescribe,a.carAccidentDate as carAccidentDate, " +
            " a.accidentType.name as accidentType,a.carAccidentPlace as carAccidentPlace from CarAccident a where  a.id =:carAccident")
    Map<String,String> getCarAccidentInfoById(@Param("carAccident") String carAccident);
}
